<template>
  <view class="container">
    <uni-forms ref="form" :modelValue="formData" :rules="rules" labelWidth="120px" labelPosition="top">
      <cu-cell-group>
        <uni-forms-item name="realWeight">
          <cu-cell title="实载重量" required>
            <input
              type="number"
              v-model="formData.realWeight"
              class="uni-input text-right"
              style="height: 100%"
              placeholder-class="placeholder__style"
              placeholder="吨"
              maxlength="10"
            />
          </cu-cell>
        </uni-forms-item>
      </cu-cell-group>
      <view class="submit-group">
        <button class="u-button" type="primary" :ripple="true" @click="submit">提交</button>
      </view>
    </uni-forms>
  </view>
</template>
<script>
import CuCellGroup from '@/components/cu-cell/cu-cell-group.vue'
import CuCell from '@/components/cu-cell/cu-cell.vue'
import { recordRealLoad } from '../../../../api/dock/trucks'

export default {
  components: {
    CuCellGroup,
    CuCell
  },
  data() {
    return {
      formData: {
        subWorkId: '',
        realWeight: ''
      },
      subWorkId: '',
      rules: {
        realWeight: {
          rules: [
            {
              required: true,
              errorMessage: '实载重量不能为空'
            }
          ]
        }
      }
    }
  },
  onLoad(option) {
    this.subWorkId = option.subWorkId
    this.formData.subWorkId = this.subWorkId
  },
  methods: {
    async submit() {
      await this.$refs.form.validate()
      recordRealLoad(this.formData).then(() => {
        this.$modal.showToast('提交成功')
        uni.navigateBack()
      })
    }
  }
}
</script>
<style lang="scss">
.container {
  .submit-group {
    background: #fff;
    z-index: 9;
    padding: 30px;
  }

  .icon-style {
    width: 46rpx;
    height: 46rpx;
  }
}
</style>
